package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.bean.NoteBean;
import flc.ast.databinding.ActivityNoteBinding;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.event.EventStatProxy;

public class NoteActivity extends BaseAc<ActivityNoteBinding> {

    @Override
    protected int onCreate() {
        return R.layout.activity_note;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivNoteBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivNoteComplete.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivNoteComplete://完成
                String title = mDataBinding.etNoteTitle.getText().toString();
                String content = mDataBinding.etNoteContent.getText().toString();
                if (TextUtils.isEmpty(title)) {
                    ToastUtils.showShort(getString(R.string.please_input_title));
                    mDataBinding.etNoteTitle.requestFocus();
                    return;
                }
                if (TextUtils.isEmpty(content)) {
                    ToastUtils.showShort(getString(R.string.please_input_content));
                    mDataBinding.etNoteContent.requestFocus();
                    return;
                }
                NoteBean bean = new NoteBean(TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd")), title, content);
                List<NoteBean> listSp = AppSpUtils.getNoteList();
                if (listSp != null && listSp.size() > 0) {
                    listSp.add(bean);
                    AppSpUtils.saveNoteList(listSp);
                } else {
                    List<NoteBean> listSave = new ArrayList<>();
                    listSave.add(bean);
                    AppSpUtils.saveNoteList(listSave);
                }
                ToastUtils.showShort(getString(R.string.save_success));
                finish();
                break;
        }
    }

    @Override
    protected void initData() {

    }

}